package com.cmos.um.service.impl;


import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.fastjson.JSONObject;
import com.cmos.csf.api.client.extend.CsfResponse;
import com.cmos.csf.client.service.api.CsfServiceCaller;
import com.cmos.um.iservice.IUserSatisfySV;
import com.cmos.um.utils.*;
import com.cmos.um.utils.http.RestClientHttpRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class UserSatisfyImpl implements IUserSatisfySV {

    private final static Logger logger = LoggerFactory.getLogger(UserSatisfyImpl.class);

    @Autowired
    private RestClientHttpRequest clien;

    /**
     * 满意度更新
     * @param params
     * @return
     */
    @Override
    public Result updateUserSatisfy(JSONObject params) {
        JSONObject jsonParams = params.getJSONObject("params");
        jsonParams.put("contactId", null);//空
        jsonParams.put("surveyTypeId", "01");//01
        jsonParams.put("userSatisfy",jsonParams.getString("userSatisfy"));//满意度按键
        jsonParams.put("userSatisfy2",jsonParams.getString("userSatisfy2"));//满意度二级按键
        jsonParams.put("userSatisfy3", null);//空
        jsonParams.put("serviceTypeId",jsonParams.getString("serviceTypeId"));//
        params.put("params",jsonParams);
        try {
            CsfResponse result = CsfServiceCaller.call(WSContent.csfUserSatisfy, params);
            if (!"0".equals(JSONObject.parseObject(result.getResponse()).getString("rtnCode"))){
                String errMessage=DataUtil.now()+"发送满意度结果失败，参数为："+params+"\r\n"+"返回的错误信息为:"+result;
                logger.error(errMessage);
                return ResultUtil.error("-9999",JSONObject.parseObject(result.getResponse()).getString("rtnMSg"));
            }
        } catch (Exception e) {
            String errMessage=DataUtil.now()+"调用更新满意度接口失败，参数为："+params+"\r\n"+"返回的错误信息为:"+e.getMessage();
            logger.error(errMessage);
            return ResultUtil.error("-9999",errMessage);
        }
        return ResultUtil.success("0","满意度回写成功！",null);
    }

}
